
var Nrgut_Num_Main = new Class({
	
	Extends: Nrg_Ut_TestCase,
	
	_original_locale: null,
	
	//--------------------------------------------------------------------------
	//--------------------------------------------------------------------------
	
	setUpBeforeClass: function()
	{
		this._original_locale = Num.locale;
		Num.locale.thousands_sep = ' ';
		Num.locale.dec_point = ',';
	},
	
	//--------------------------------------------------------------------------
	
	tearDownAfterClass: function()
	{
		Num.locale = this._original_locale;
	},
	
	//--------------------------------------------------------------------------
	
	testFormatStrict: function()
	{
		var tnn = 1.23456;
		var tnt = '1 234,56789';
		
		var N0 = new Num(tnt);
		
		this.assertInstanceOf( Num.strict(tnt), Number );
		this.assertTypeOf( Num.strict(tnt), 'number' );
		this.assertEquals( Num.strict(tnt), 1234.56789 );
		this.assertEquals( N0.valueOf(), 1234.56789 );
	},
	
	//--------------------------------------------------------------------------
	
	testConstructor: function()
	{
		var n0 = new Num('123.12345678901234567890');
		
		this.assertInstanceOf( n0.valueOf(), Number );
		this.assertTypeOf( n0.valueOf(), 'number' );
		this.assertEquals( new Num(.12345), '0.12345' );
		this.assertEquals( new Num(-.434343), '-0.434343' );
		this.assertEquals( new Num(-12.345), '-12.345' );
	},
	
	//--------------------------------------------------------------------------
	
	testBaseBigDec: function()
	{
		var n0 = new Num('123.12345678901234567890');
		var n1 = new Num('-123.12345678901234567890');
		
		this.assertEquals( n0.valueOf(), '123.12345678901234567890' );
		this.assertEquals( n1.valueOf(), '-123.12345678901234567890' );
	},
	
	//--------------------------------------------------------------------------
	
	testFormatMinFixed: function()
	{
		var n0 = new Num(2.3456);
		var n1 = new Num(4.5);
		
		this.assertInstanceOf( n0.formatMinFixed(), String );
		this.assertEquals( n0.formatMinFixed(1), '2.3456');
		this.assertEquals( n0.formatMinFixed(2), '2.3456');
		this.assertEquals( n0.formatMinFixed(), '2.3456');
		this.assertEquals( n0.formatMinFixed(3), '2.3456');
		this.assertEquals( n0.formatMinFixed(4), '2.3456');
		this.assertEquals( n0.formatMinFixed(5), '2.34560');
		this.assertEquals( n1.formatMinFixed(5), '4.50000');
	},
	
	//--------------------------------------------------------------------------
	
	testFormatMinFixedNegative: function()
	{
		var n0 = new Num(-2.3456);
		var n1 = new Num(-4.5);
		
		this.assertEquals( n1.formatMinFixed(), '-4.50');
		this.assertEquals( n0.formatMinFixed(1), '-2.3456');
		this.assertEquals( n0.formatMinFixed(2), '-2.3456');
		this.assertEquals( n0.formatMinFixed(), '-2.3456');
		this.assertEquals( n0.formatMinFixed(3), '-2.3456');
		this.assertEquals( n0.formatMinFixed(4), '-2.3456');
		this.assertEquals( n0.formatMinFixed(5), '-2.34560');
		this.assertEquals( n1.formatMinFixed(5), '-4.50000');
		this.assertEquals( n1.formatMinFixed(), '-4.50');
	},
	
	//--------------------------------------------------------------------------
	
	testFormatFixed: function()
	{
		var n0 = new Num(2.3456);
		var n1 = new Num(1.25);
		var n2 = new Num(234);
		
		this.assertEquals( n0.formatFixed(2), '2.35' );
		this.assertEquals( n0.formatFixed(1), '2.3' );
		this.assertEquals( n0.formatFixed(5), '2.34560' );
		this.assertEquals( n0.formatFixed(7), '2.3456000' );
		
		this.assertEquals( n1.formatFixed(7), '1.2500000' );
		
		this.assertEquals( n2.formatFixed(2), '234.00' );
	},
	
	//--------------------------------------------------------------------------
	
	testFormatFixedNegative: function()
	{
		var n0 = new Num(-2.3456);
		var n1 = new Num(-1.25);
		var n2 = new Num(-234);
		
		this.assertEquals( n0.formatFixed(2), '-2.35' );
		this.assertEquals( n0.formatFixed(1), '-2.3' );
		this.assertEquals( n0.formatFixed(5), '-2.34560' );
		this.assertEquals( n0.formatFixed(7), '-2.3456000' );
		
		this.assertEquals( n1.formatFixed(7), '-1.2500000' );
		
		this.assertEquals( n2.formatFixed(2), '-234.00' );
	},
	
	//--------------------------------------------------------------------------
	
	testFormatThousandsSep: function()
	{
		var n0 = new Num('1234567890,12345');
		this.assertInstanceOf( n0.formatThousandsSep(), String );
		this.assertEquals( new Num(123.456), '123.456' );
		this.assertEquals( n0.formatThousandsSep(), '1 234 567 890.12345' );
		this.assertEquals( n0.formatThousandsSep(','), '1,234,567,890.12345' );
		
		n0 = new Num('-1234567890,12345');
		n1 = new Num('-123456789012,12345');
		this.assertEquals( new Num(-123.456), '-123.456' );
		this.assertEquals( n0.formatThousandsSep(), '-1 234 567 890.12345' );
		this.assertEquals( n0.formatThousandsSep(','), '-1,234,567,890.12345' );
		this.assertEquals( n1.formatThousandsSep(), '-123 456 789 012.12345' );
	},
	
	//--------------------------------------------------------------------------
	
	testFormatDecPoint: function()
	{
		var n0 = new Num('1.23');
		
		this.assertEquals( n0.formatDecPoint(), '1,23' );
		this.assertEquals( n0.formatDecPoint('.'), '1.23' );
		
		n0 = new Num('-1.23');
		
		this.assertEquals( n0.formatDecPoint(), '-1,23' );
		this.assertEquals( n0.formatDecPoint('.'), '-1.23' );
	},
	
	//--------------------------------------------------------------------------
	
	testFormat: function()
	{
		var n0 = new Num('1.23');
		var n1 = new Num('1234567890.123456789');
		var n2 = new Num('123456789.123456789');
		var n3 = new Num('12345678.123456789');
		
		this.assertEquals( n0.format(2), '1.23' );
		this.assertEquals( n0.format(3), '1.230');
		this.assertEquals( n0.format(4, ','), '1,2300');
		
		this.assertEquals( n1.format(2), '1234567890.12' );
		this.assertEquals( n1.format(5), '1234567890.12346' );
		this.assertEquals( n1.format(7, ','), '1234567890,1234568' );
		this.assertEquals( n1.format(6, ',', ' '), '1 234 567 890,123457' );
		
		this.assertEquals( n2.format(3, ',', ' '), '123 456 789,123' );
		this.assertEquals( n3.format(3, ',', ' '), '12 345 678,123' );
	},
	
	//--------------------------------------------------------------------------
	
	testFormatNegative: function()
	{
		var n0 = new Num('-1.23');
		var n1 = new Num('-1234567890.123456789');
		var n2 = new Num('-123456789.123456789');
		var n3 = new Num('-12345678.123456789');
		
		this.assertEquals( n0.format(2), '-1.23' );
		this.assertEquals( n0.format(3), '-1.230');
		this.assertEquals( n0.format(4, ','), '-1,2300');
		
		this.assertEquals( n1.format(2), '-1234567890.12' );
		this.assertEquals( n1.format(5), '-1234567890.12346' );
		this.assertEquals( n1.format(7, ','), '-1234567890,1234568' );
		this.assertEquals( n1.format(6, ',', ' '), '-1 234 567 890,123457' );
		
		this.assertEquals( n2.format(3, ',', ' '), '-123 456 789,123' );
		this.assertEquals( n3.format(3, ',', ' '), '-12 345 678,123' );
	}
	
	//--------------------------------------------------------------------------
});